﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package com.facebook.utils {
    import com.facebook.data.*;
    import com.facebook.data.users.*;

    public class FacebookUserXMLParser {

        protected static function parseWorkHistory(_arg1:XML, _arg2:Namespace):Array{
            var _local5:Object;
            var _local6:FacebookWorkInfo;
            var _local3:Array = [];
            var _local4:XMLList = _arg1.children();
            for each (_local5 in _local4) {
                _local6 = new FacebookWorkInfo();
                _local6.location = FacebookXMLParserUtils.createLocation(_local5._arg2::location[0], _arg2);
                _local6.company_name = String(_local5._arg2::company_name);
                _local6.description = String(_local5._arg2::description);
                _local6.position = String(_local5._arg2::position);
                _local6.start_date = FacebookDataUtils.formatDate(_local5._arg2::start_date);
                _local6.end_date = FacebookDataUtils.formatDate(_local5._arg2::end_date);
                _local3.push(_local6);
            };
            return (_local3);
        }
        protected static function createStatus(_arg1:XML, _arg2:Namespace):StatusData{
            var _local3:StatusData = new StatusData();
            _local3.message = String(_arg1._arg2::message);
            _local3.time = FacebookDataUtils.formatDate(String(_arg1._arg2::time));
            return (_local3);
        }
        protected static function parseEducationHistory(_arg1:XML, _arg2:Namespace):Array{
            var _local5:Object;
            var _local6:FacebookEducationInfo;
            var _local7:XML;
            var _local3:Array = [];
            var _local4:XMLList = _arg1.children();
            for each (_local5 in _local4) {
                _local6 = new FacebookEducationInfo();
                _local6.name = String(_local5._arg2::name);
                _local6.year = String(_local5._arg2::year);
                _local6.degree = String(_local5._arg2::degree);
                _local6.concentrations = [];
                for each (_local7 in _local5.concentration) {
                    _local6.concentrations.push(_local7);
                };
                _local3.push(_local6);
            };
            return (_local3);
        }
        public static function createFacebookUser(_arg1:XML, _arg2:Namespace):FacebookUser{
            var _local6:XML;
            var _local7:String;
            var _local3:FacebookUser = new FacebookUser();
            var _local4:XMLList = _arg1.children();
            var _local5:uint = _local4.length();
            var _local8:uint;
            while (_local8 < _local5) {
                _local6 = _local4[_local8];
                _local7 = _local6.localName().toString();
                switch (_local7){
                    case "status":
                        _local3[_local7] = createStatus(_local6, _arg2);
                        break;
                    case "affiliations":
                        _local3[_local7] = createAffiliations(_local6.children(), _arg2);
                        break;
                    case "hometown_location":
                    case "current_location":
                        _local3[_local7] = FacebookXMLParserUtils.createLocation(_local6, _arg2);
                        break;
                    case "profile_update_time":
                        _local3[_local7] = FacebookDataUtils.formatDate(_local6.toString());
                        break;
                    case "hs_info":
                        _local3.hs1_id = parseInt(_local6._arg2::hs1_id);
                        _local3.hs1_name = String(_local6._arg2::hs1_name);
                        _local3.hs2_id = parseInt(_local6._arg2::hs2_id);
                        _local3.hs2_name = String(_local6._arg2::hs2_name);
                        _local3.grad_year = String(_local6._arg2::grad_year);
                        break;
                    case "education_history":
                        _local3[_local7] = parseEducationHistory(_local6, _arg2);
                        break;
                    case "work_history":
                        _local3[_local7] = parseWorkHistory(_local6, _arg2);
                        break;
                    case "timezone":
                    case "notes_count":
                    case "wall_count":
                        _local3[_local7] = Number(_local6.toString());
                        break;
                    case "has_added_app":
                    case "is_app_user":
                        _local3[_local7] = FacebookXMLParserUtils.toBoolean(_local6);
                        break;
                    case "meeting_sex":
                    case "meeting_for":
                    case "email_hashes":
                        _local3[_local7] = toArray(_local6, _arg2);
                        break;
                    default:
                        if ((_local7 in _local3)){
                            _local3[_local7] = String(_local6);
                        };
                };
                _local8++;
            };
            return (_local3);
        }
        protected static function toArray(_arg1:XML, _arg2:Namespace):Array{
            var _local3:Array = [];
            var _local4:XMLList = _arg1.children();
            var _local5:uint = _local4.length();
            var _local6:uint;
            while (_local6 < _local5) {
                _local3.push(_local4[_local6].toString());
                _local6++;
            };
            return (_local3);
        }
        protected static function createAffiliations(_arg1:XMLList, _arg2:Namespace):Array{
            var _local4:*;
            var _local5:FacebookNetwork;
            var _local3:Array = [];
            for each (_local4 in _arg1) {
                _local5 = new FacebookNetwork();
                _local5.nid = parseInt(_local4._arg2::nid);
                _local5.name = String(_local4._arg2::name);
                _local5.type = String(_local4._arg2::type);
                _local5.status = String(_local4._arg2::status);
                _local5.year = String(_local4._arg2::year);
                _local3.push(_local5);
            };
            return (_local3);
        }

    }
}//package com.facebook.utils 
